#pragma once

#include <memory>
#include <unordered_map>
#include <vector>
#include <mutex>
#include <any>
#include <atomic>
#include "zrpc/base/time_stamp.h"
#include "zrpc/net/callback.h"
#include "zrpc/net/channel.h"

namespace zrpc {
class Timer {
 public:
  Timer(TimerCallback &&cb, TimeStamp &&expiration, bool repeat,
        double interval);

  ~Timer();

  void Run();
  int64_t GetSequence();
  int64_t GetWhen();
  TimeStamp &GetExpiration();
  bool GetRepeat();
  void SetSequence(int64_t seq);
  void Restart(const TimeStamp &now);
  double GetInterval();

 private:
  Timer(const Timer &);

  void operator=(const Timer &);

  bool repeat_;
  double interval_;
  int64_t sequence_;
  TimeStamp expiration_;
  TimerCallback callback_;
  static std::atomic<int64_t> g_num_reated;
};
}  // namespace zrpc